package com.echo.blog.business.blog.controller;

import com.echo.blog.business.blog.service.IBlogTagService;
import com.echo.model.constant.response.ResponseData;
import com.echo.model.utils.StringUtils;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author chentl
 * @version V1.0
 * @Project BlogTagController
 * @Title BlogTagController.java
 * @Description blog 控制器
 * @Package com.echo.blog.business.blog.controller
 * @date 2019/9/5 18:03
 * @Copyright: 上海顺益信息科技有限公司 All rights reserved.
 */
@RestController
@Slf4j
@RequestMapping("/blogTag")
public class BlogTagController {

    @Autowired
    private IBlogTagService blogTagService;

    @RequestMapping(value = "/list")
    public ResponseData getBlogList() {
        List<Map<String, Object>> list = blogTagService.getBloyTagList();
        return new ResponseData(true, 200, "成功", list);
    }

    @RequestMapping(value = "/add")
    public ResponseData add(String tagName) {
        if(StringUtils.isBlank(tagName)){
            return ResponseData.error("tagName不能为空!");
        }
        //添加博客标签
        blogTagService.insertBlogTagByName(tagName);

        List<Map<String, Object>> list = blogTagService.getBloyTagList();
        return new ResponseData(true, 200, "成功", list);
    }


}
